package com.carmanage.domain;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Entity
@Table(name="user")
@Scope("prototype")
public class User {
    
	@Id
	@GeneratedValue
	private int userid;
	
	private String username;
	private String password;

	
	public User(){};
	public User(String username, String password) {
		super();
		this.username = username;
		this.password = password;
	}


	@ManyToMany(cascade ={CascadeType.PERSIST,CascadeType.MERGE}, fetch = FetchType.EAGER,mappedBy="users")
	private Set<Role> roles;

	public int getUserid() {
		return userid;
	}

	public void setUserid(int userid) {
		this.userid = userid;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
    
	
	public Set<Role> getRoles() {
		return roles;
	}

	
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	@Override
	public String toString() {
		return "User [userid=" + userid + ", username=" + username
				+ ", password=" + password + ", roles=" + roles + "]";
	}
	
	
	
}
